package com.itheima.test7;

import java.io.*;
import java.net.Socket;

/**
 * @Author:gy
 * @Date: 2025/09/04 10:50
 * @Description:
 */
public class ClientDemo {
    public static void main(String[] args) throws Exception {
        //1
        Socket socket = new Socket("127.0.0.1",10086);
        //获得输出流
        OutputStream os = socket.getOutputStream();
        os.write("hello".getBytes());
      //  os.close(); 这里不能关流
        //Socket 关闭的时候  会给一个结束的标记 我们可以手动给一个结束标记
        socket.shutdownOutput();

        //4.接受服务端的反馈
        // InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        //byte[] buffer = new byte[1024];
        /*int len;
        while ((len = is.read(buffer)) != -1) {
            System.out.println(new String(buffer,0,len));
        }*/
       /* int b;
        while ((b = is.read()) != -1) {
            System.out.println((char)b);
        }*/
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        br.close();
        socket.close();
    }
}
